import sys

from utils.logger_util import logger

sys.path.append('d:\\Code\\2025\\Projects\\lottery-system\\lottery-system\\integration-tests')
from utils.database_util import DatabaseUtil
from utils.yaml_util import read_yaml

# Load local database configuration
config = read_yaml('db_config.yaml', 'local_config')
log=logger.getlog()
db_util = None
try:
    db_util = DatabaseUtil(
        username=config['username'],
        password=config['password'],
        host=config['host'],
        port=config['port'],
        database=config['database']
    )
    if db_util.test_connection():
        log.info('数据库连接成功！')
    else:
        log.error('数据库连接失败。')
except Exception as e:
    log.error(f'连接数据库时发生错误********: {e}')
    if db_util:
        log.error(f'DatabaseUtil object attributes: {dir(db_util)}')
finally:
    if db_util:
        db_util.close()